49

Explore Your Deductive Logic—Sudoku

49

You might be wondering, how many more algorithms can we think of to refine the

answers for a Sudoku puzzle? The answer is as difficult as the question “How many

bugs are there in my program?” It is what mathematicians call an “indeterminate”

number—​it is not possible to calculate it. I guess there is no algorithm to calculate

how many algorithms are possible to solve a problem—​you only know the number

of algorithms that have been discovered, similar to the number of bugs in a program

that have been uncovered.

9

7

3

9

1

(2,6)

(2,6)

8

1

3

4

8

5

5

7

1

8

4

COLUMN 1 2 3 4 5 6 7 8 9

9 8 7 6 5 4 3 2 1

ROW

FIGURE 3.5  Love-​locked pair.

3.5  LOVE-LOCKED PAIR

The next algorithm I am going to discuss identifies a “pair”—​to help you remember

it, I will call it a “love-​locked” pair. The point is that if two numbers are the only two

possible solutions for two cells in a row, then those two numbers cannot be solutions

for any other cells in the same row. Even though it may seem fairly obvious, it does

need some smart manipulation of variables to execute it. In the example above, row

3 columns 2 and 6 have the same “love-​locked” pair of numbers that will potentially

fill them—​2 and 6. But that means 2 and 6 cannot be anywhere else in the same row.

In the next few steps, I will explain how you can utilize this valuable insight in

your algorithm.

STEP 11

The first step is to identify the candidates for each cell and store them away. In

order to do this we count the number of items in our cantbelist array. Only those

who have 7 are candidates.

For i =​ 1 To 9

For j =​ 1 To 9

    cantbelistcount(i, j) =​ 0

    For k =​ 1 To 9

      If cantbelist(i, j, k) <> 0 Then

        cantbelistcount(i, j) =​ cantbelistcount(i, j) +​ 1

      End If

    Next k